<?php
/**
 * 历史数据的处理,通过调用bll方法，写入数据
 */
apf_require_class('Oa_Job_Attendance_Abstract');
apf_require_class("Tools_Tools");

apf_require_class('Const_LeaveType');
apf_require_class('Bll_Attendance_DailyReport');
apf_require_class('Bll_Attendance_DailyLeave');
apf_require_class('Bll_Attendance_AccessDayRecord');

class Oa_Job_Attendance_SplitOldLeaveRecord extends Oa_Job_Attendance_Abstract {
    /** 考勤系统读 **/
    private $readdb = "attendance_slave";
    /** 考勤系统写 **/
    private $writedb = "attendance_master";

    public function run(){
        $start = 0;
        $daily_bll = new Bll_Attendance_DailyReport();
        while (true){
            $sql_gc = "SELECT * FROM leave_record WHERE id>$start AND end_time>'2012-06-31 00:00' limit 10";
            $datalist=$this->get_rows($sql_gc,array(),false,$this->writedb);
            if(empty($datalist)) {
                break;
            }

            foreach ($datalist as $leave_data) {
                $leave_data['start_time'] = strtotime($leave_data['start_time']);
                $leave_data['end_time'] = strtotime($leave_data['end_time']);
                //print_r($leave_data);
                echo $leave_data['type'];
                $leave_data['type'] = $daily_bll->format_leave_type($leave_data['type']);
                $leave_data['status']=$daily_bll->format_leave_status($leave_data['status']);
                $leave_data['daylist']=$daily_bll->format_leave_days($leave_data['start_time'],$leave_data['end_time'],$leave_data['type']);
                $type=$leave_data['type'];
                var_dump($type);
                var_dump(Const_LeaveType::LEAVE_TYPE_GONGCHU);

                switch ($type){
                    case Const_LeaveType::LEAVE_TYPE_CHIDAO:
                        $daily_bll->update_come_late($leave_data,100);
                        break;
                    case Const_LeaveType::LEAVE_TYPE_ZAOTUI:
                        $daily_bll->update_left_early($leave_data,100);
                        break;
                    case Const_LeaveType::LEAVE_TYPE_GONGCHU:
                        $daily_bll->update_business_travel($leave_data,100);
                        break;
                    case Const_LeaveType::LEAVE_TYPE_CHUCHA:
                        $daily_bll->update_business_trip($leave_data, 100);
                        break;
                    default:
                        $daily_bll->update_common_leave($leave_data,100);
                        break;
                }
            }//exit;
            $num = count($datalist);
            $start = $datalist[$num-1]['id'];
        }
        $this->log('ok');
    }

}